home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 60.zip / BS1 part 60 / C mon v3 d3.adf / CMANV3_3.LHA / ACE9.lha / System / DirtyInput / Keyboard.c < prev    next >
C/C++ Source or Header  |  1992-05-03  |  3KB  |  70 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Intuition               Amiga C Club       */
  7. /* Chapter: DirtyInput                  Tulevagen 22       */
  8. /* File:    Keyboard.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-02                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* Keyboard() is a handy, easy and fast but naughty function that hits */
  21. /* the hardware of the Amiga. It checks the keyboard, and returns the  */
  22. /* Raw Key Code. (See chapter (C) SYSTEM DEFAULT CONSOLE KEY MAPPING   */
  23. /* for the full list of Raw Key Codes.)                                */
  24. /*                                                                     */
  25. /* Synopsis: value = Keyboard();                                       */
  26. /*                                                                     */
  27. /* value:    (UBYTE) Raw Key Code. For example: If the user hits key   */
  28. /*           "N", the function returns 36 (hexadecimal). When the user */
  29. /*           releases the key, B6 is returned.                         */
  30.  
  31.  
  32. #include <exec/types.h>
  33. #include <hardware/cia.h>
  34.  
  35.  
  36.  
  37. /* This will automatically be linked to the CIA A (8520) chip: */
  38. extern struct CIA far ciaa;
  39.  
  40.  
  41.  
  42. void main();
  43. UBYTE Keyboard( void );
  44.  
  45.  
  46. void main()
  47. {
  48.   int loop;
  49.   
  50.   for( loop = 0; loop < 100; loop++ )
  51.     printf("Code: %2x\n", Keyboard() );
  52. }
  53.  
  54.  
  55.  
  56. UBYTE Keyboard( void )
  57. {
  58.   UBYTE code;
  59.  
  60.   /* Get a copy of the SDR value and invert it: */
  61.   code = ciaa.ciasdr ^ 0xFF;
  62.   
  63.   /* Shift all bits one step to the right, and put the bit that is */
  64.   /* pushed out last: 76543210 -> 07654321                         */
  65.   code = code & 0x01 ? (code>>1)+0x80 : code>>1;
  66.  
  67.   /* Return the Raw Key Code Value: */
  68.   return( code );
  69. }
  70.